<template>
	<view :class="['search', {actived:Number(gradientScale)>0.5}, {'max-search':!clientRect.width}]"
		:style="{'background':`rgba(255, 255, 255, ${gradientScale})`, 'padding-top':`${clientRect.top}px`}">
		<view class="icon">
			<image class="img1" src="/static/images/logo-ak.svg" mode="widthFix" />
			<image class="img2" src="/static/images/logo-kok.svg" :style="{opacity:gradientScale}" mode="widthFix" />
		</view>
		<view class="inp" :style="{'height':`${clientRect.height}px`,'border-radius':`${clientRect.height/2}px`}">
			<view class="left" @click='handleSearch'>
				<text class="cuIcon-search icon"></text>
				<text class="btn">ئىزدەش</text>
			</view>
			<view class="right">
				<input v-model="keyword" class="input" type="text" placeholder="فىلىم ئىزدەش">
			</view>
		</view>
		<view class="blank" :style="{width:`${clientRect.width}px`}"></view>
	</view>
</template>

<script>
	import {
		height,
		top,
		width,
	} from '@/scripts/compatible/clientRect.js'
	export default {
		props: {
			gradientScale: {
				type: String | Number,
				require: true,
			},
		},
		data() {
			return {
				clientRect: {
					height: 32,
					top: 12,
					width: 0,
				},
				keyword: '',
			}
		},
		mounted() {
			this.getWindowByWxMenuBtn()
		},
		methods: {
			handleSearch() {
				uni.navigateTo({
					url: '/pages/search/index?keyword=' + this.keyword
				})
			},
			getWindowByWxMenuBtn() {
				const clientRect = {
					height,
					top,
					width,
				}
				this.$set(this, 'clientRect', clientRect)
			},
		},
	}
</script>

<style lang="scss" scoped>
	.search {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 10;
		height: max-content;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 10px 12px;
		width: 100%;
		box-sizing: border-box;

		&.max-search {
			.inp {
				max-width: 200px;
			}
		}

		&.actived {
			.img1 {
				opacity: 0;
			}

			.inp {
				color: #666;
				background-color: #f0f0f0;
				border-color: #f0f0f0;
			}
		}

		.icon {
			width: 24px;
			// height: 32px;
			position: relative;

			.img1,
			.img2 {
				display: block;
				width: 100%;
				height: 100%;
			}

			.img1 {
				position: relative;
				z-index: 1;
			}

			.img2 {
				position: absolute;
				z-index: 2;
				top: 1px;
				left: 0;
			}
		}

		.inp {
			display: flex;
			justify-content: space-between;
			align-items: center;
			// height: 32px;
			// border-radius: 16px;
			box-sizing: border-box;
			background-color: rgba(255, 255, 255, 0.506);
			border: 1px solid rgba(255, 255, 255, 0.322);
			padding: 0 10px;
			color: #fff;
			font-size: 12px;
			// max-width: 200px;
			flex: 1;
			margin: 0 12px;

			.icon {
				font-size: 16px;
			}

			.btn {
				margin: 0 10px 0 5px;
				position: relative;
				bottom: 2px;
			}

			.input {
				flex: 1;
				text-align: right;
				font-size: 12px;
				text-indent: 1em;
			}
		}

		.blank {
			height: 1px;
		}
	}
</style>